<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理员登录</title>
    <meta name="robots" content="noindex, nofollow">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/resource/backend/css/font.css">
    <link rel="stylesheet" href="/resource/backend/css/weadmin.css">
    <script src="/resource/backend/lib/layui/layui.js" charset="utf-8"></script>
    <style>
        #captcha {
            cursor: pointer;
        }
    </style>
</head>
<body class="login-bg">
<div class="login">
    <div class="message">${ system_setting "web_name" }$ 后台管理</div>
    <div id="darkbannerwrap"></div>

    <form method="post" class="layui-form">
        <input name="username" placeholder="用户名" type="text" class="layui-input">
        <hr class="hr15">
        <input name="password" placeholder="密码" type="password" class="layui-input">
        <hr class="hr15">
        <div class="layui-form-item">
            <div class="layui-col-xs6">
                <input name="captcha_str" placeholder="验证码" type="text" class="layui-input">
                <input name="captcha_id" id="captcha_id" type="hidden" class="layui-input">
            </div>
            <div class="layui-col-xs6">
                <img src="/resource/backend/images/loading.gif" id="captcha_img"
                     style="margin:auto;height:50px;display:table-cell;cursor:pointer;">
            </div>

        </div>
        <hr class="hr15">
        <input class="loginin" value="登录" lay-submit lay-filter="login" style="width:100%;" type="button">
        <hr class="hr20">

    </form>
</div>

<script type="text/javascript">

    layui.extend({
        admin: '/resource/backend/js/admin'
    });
    layui.use(['form', 'admin', 'jquery'], function () {
        var form = layui.form
            , admin = layui.admin
            , $ = layui.$;

        //刷新验证码方法
        function reloadCaptcha() {
            $.get('${ backend_api_url "/captcha/get" }$', {time: new Date().getTime()}, function (res) {
                $('#captcha_img').attr('src', res.data['b64s'])
                $('#captcha_id').val(res.data['id'])
            })
        }

        reloadCaptcha()
        $('#captcha_img').click(function () {
            reloadCaptcha();
        });
        //监听提交
        form.on('submit(login)', function (data) {
            var data = $("form").serialize();
            $.post('${ backend_api_url "/admin/login" }$', data, function (result) {
                console.log(result)
                if (!result.code) {
                    layer.msg(result.message, {
                        icon: 6
                        , time: 500
                    }, function () {
                        location.href = '${ backend_url "/" }$'
                    })
                } else {
                    //刷新验证码
                    reloadCaptcha();
                    layer.msg(result.message, {
                        icon: 5
                        , anim: 6
                        , time: 2000
                    });
                }
            });

            return false;
        });
        //用户名获取焦点
        $('.layui-form input').eq(0).focus();
        //回车登录
        $(window).keydown(function (e) {
            e = e || event;
            if (e.keyCode == 13) {
                $('.loginin').trigger("click");
            }
        });
        //判断当前页面如果在iframe中,将框架中的页面显示到top.location
        if (self.frameElement && self.frameElement.tagName == "IFRAME") {
            var selfUrl = self.location.href;
            top.location.href = selfUrl;
        }
    });

</script>

<!-- 底部结束 -->
</body>
</html>